//
//  TestTableViewController.m
//  HYSmileiOS
//
//  Created by SMC-MAC on 16/4/26.
//  Copyright © 2016年 heyou. All rights reserved.
//

/**
 *  定义测试模块名称
 */

#define AFNetworking    @"AFNetworking"
#define LKDBHelper      @"LKDBHelper"
#define SDWebImage      @"SDWebImage"

#import "TestTableViewController.h"
#import "TestAFViewController.h"

@interface TestTableViewController ()
{
    NSArray<NSString*> *_modules;
}
- (IBAction)onCancelButtonClicked:(id)sender;

@end

@implementation TestTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    [self prepareData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- prepare data
- (void)prepareData {
    _modules = @[AFNetworking, LKDBHelper, SDWebImage];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _modules.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString* testCell = @"testCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:testCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:testCell];
    }
    
    // Configure the cell...
    cell.textLabel.text = [_modules objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    NSString *moduleName = [_modules objectAtIndex:indexPath.row];
    NSString *controllerName = @"";
    if ([moduleName isEqualToString:AFNetworking]) {
        controllerName = @"TestAFViewController";
    } else if ([moduleName isEqualToString:LKDBHelper]) {
        controllerName = @"";
    } else if ([moduleName isEqualToString:SDWebImage]) {
        controllerName = @"TestSDWebImageViewController";
    }
    
    if (controllerName && controllerName.length > 0) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil];
        UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:controllerName];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark -- right close button
- (IBAction)onCancelButtonClicked:(id)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
@end
